<template>
  <div class="register">
    <div class="logo">
      <img src="../static/images/logo.png" alt="" />
    </div>

    <div class="form_container">
      <van-form>
        <van-field
          v-model="username"
          name="username"
          label="昵称"
          placeholder="昵称不得多于8字"
          :rules="[{ required: true, message: '请填写昵称' }]"
        />
        <van-field
          v-model="password"
          type="password"
          name="password"
          label="密码"
          placeholder="8到12位至少两种字符"
          :rules="[{ required: true, message: '请填写密码' }]"
        />
        <van-field
          v-model="again_password"
          type="again_password"
          name="确认"
          label="确认"
          placeholder="再次确认密码"
          :rules="[{ required: true, message: '请再次确认密码' }]"
        />
        <div class="enter_button">
          <img src="../static/images/enter_button.png" alt="" />
          <van-button
            round
            block
            type="info"
            native-type="submit"
            @click="subBtn"
            >提交</van-button
          >
        </div>
      </van-form>
    </div>

    <div class="foot">
      <div>同意协议</div>
      <div class="login_click" @click="login">我要登录</div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      username: "",
      password: "",
      user_tel: "",
      again_password: "",
    };
  },
  created() {
    const user_tel = this.$route.query;
    this.user_tel = user_tel.user_tel;
  },
  methods: {
    async subBtn() {
      if (this.password == this.again_password) {
        const res = await this.request.post("/register", {
          user_tel: this.user_tel,
          password: this.password,
          username: this.username,
        });
        if (res.status != 0) {
          return this.$toast.fail("输入错误!");
        } else {
          this.$router.push({ path: "/main" });
        }
      }
    },
    login() {
      this.$router.push({ path: "/login" });
    },
  },
};
</script>

<style lang="less" scoped>
.register {
  width: 750rpx;
  height: 100%;
  margin: 0 auto;
  .van-field__control {
    width: 84.5%;
    background-color: rgb(244, 244, 244);
    border-radius: 10px;
  }
  .logo {
    padding: 16.7% 0 8.6%;
    width: 69.3%;
    height: 13.2%;
    margin: 0 auto;
  }

  .logo img {
    width: 100%;
    height: 100%;
  }

  .form_container {
    width: 65.2%;
    height: 27.3%;
    margin: 0 auto;
  }

  .enter_button {
    box-sizing: border-box;
    position: relative;
    padding: 8% 0 0 0;
    width: 22.4%;
    height: 24.7%;
    margin: 0 auto;
    display: block;
  }

  .enter_button button {
    background: none;
    border: none;
    border-radius: 50%;
    font-size: 0;
  }

  .enter_button > img {
    position: absolute;
    width: 100%;
    top: 24.7%;
    left: 0;
  }

  .form_container .login_field,
  .form_container .register_field:not(.security_code) {
    box-sizing: border-box;
    width: 100%;
    height: 18.5%;
    padding: 6% 0 0 8%;
    margin-bottom: 14.9%;
    background-color: rgb(244, 244, 244);
    border-radius: 59px;
  }

  .van-field__body {
    height: 37.3%;
    align-items: baseline;
  }

  .van-field__control::-webkit-input-placeholder {
    color: rgb(144, 144, 144);
    font-family: "Adobe Heiti Std";
  }

  .foot {
    position: fixed;
    width: 70.9%;
    padding: 0 14%;
    bottom: 7.5%;
    font-family: "SourceHanSansCN";
    font-weight: 600;
    font-size: 0.5em;
  }

  .foot div {
    display: inline-block;
  }

  .foot .login_click {
    float: right;
  }
}
</style>